<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" title="转账审核" width="500px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
      <el-form-item label="转账类型">
        <template>
            <div v-if="form.transferType==0"> 对私转账</div>
            <div v-else>对公转账</div>
        </template>
      </el-form-item>
      <el-form-item label="用户名称">
        <el-input disabled v-model="form.userName" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="账户名称" v-if="form.transferType == 0">
        <el-input disabled v-model="form.accountName" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="公司名称" v-if="form.transferType == 1">
        <el-input disabled v-model="form.corporationName" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="银行卡号">
        <el-input disabled v-model="form.bankCode" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="开户行地址">
        <el-input disabled v-model="form.bankAddress" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="转账金额(元)">
        <el-input disabled v-model="form.amount" style="width: 350px;" />
      </el-form-item>
      <el-form-item label="审核状态">
        <el-radio v-model="form.approvalStatus" v-if="form.approvalStatus == -1" :label="-1">不通过</el-radio>
        <el-radio v-model="form.approvalStatus" v-if="form.approvalStatus == 0" :label="0">审核中</el-radio>
        <el-radio v-model="form.approvalStatus" v-if="form.approvalStatus == 1" :label="1">待转账</el-radio>
        <el-radio v-model="form.approvalStatus" v-if="form.approvalStatus == 2" :label="2">已转账</el-radio>
      </el-form-item>
      <el-form-item label="审核结果">
        <el-radio v-model="form.approvalResult" :label="1">通过</el-radio>
        <el-radio v-model="form.approvalResult" :label="0">不通过</el-radio>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.mark" style="width: 350px;" rows="5" type="textarea" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/userTransfer'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        uid: '',
        userName: '',
        transferType: '',
        accountName: '',
        corporationName: '',
        bankCode: '',
        bankAddress: '',
        amount: '',
        mark: '',
        approvalStatus: '',
        approvalResult: ''
      },
      rules: {
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      this.loading = true
      if (this.isAdd) {
        this.doAdd()
      } else this.doEdit()
    },
    doAdd() {
      add(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '审核成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        uid: '',
        userName: '',
        transferType: '',
        accountName: '',
        corporationName: '',
        bankCode: '',
        bankAddress: '',
        amount: '',
        mark: '',
        approvalStatus: '',
        approvalResult: ''
      }
    }
  }
}
</script>

<style scoped>

</style>
